package myJs

import myJs.login.Login
import myJs.myPkg._
import myJs.user.UserCp
import slinky.core._
import slinky.core.annotations.react
import slinky.web.html._
import cps._
import myJs.admin.AdminCp

@react object App {

  type Props = Unit

  val component = FunctionalComponent[Props] { props =>
    val location = ReactRouterDOM.useLocation()
    div(className := "App")(
      Routes(
        Route(path = "", element = Login.cpE),
        Route(path = MyPage.register.path, element = MyPage.register.cpE),
        Route(path = MyPage.registerActive.path, element = MyPage.registerActive.cpE),
        Route(path = MyPage.confirmActive.path, element = MyPage.confirmActive.cpE),
        Route(path = MyPage.recoverPassword.path, element = MyPage.recoverPassword.cpE),
        Route(path = MyPage.newPasswordActive.path, element = MyPage.newPasswordActive.cpE),
        Route(path = MyPage.newPassword.path, element = MyPage.newPassword.cpE),
        Route(path = MyPage.user.prefix, element = UserCp())(
          MyPage.user.pages.map { x =>
            val finalCp = TransitionGroup(
              CSSTransition(key = x.path, classNames = "fade", timeout = 300, location = location)(
                x.cpE
              )
            )
            Route(key = x.path, path = x.path, element = finalCp)
          },
          Route(path = "*", element = NotFoundCp())
        ),
        Route(path = MyPage.admin.prefix, element = AdminCp())(
          MyPage.admin.registerPages.map { x =>
            val finalCp = TransitionGroup(
              CSSTransition(key = x.path, classNames = "fade", timeout = 300, location = location)(
                x.cpE
              )
            )
            Route(key = x.path, path = x.path, element = finalCp)
          },
          Route(path = "*", element = NotFoundCp())
        ),
      )
    )

  }

}
